package com.huishi.entity;

import com.huishi.ui.FileChooserUI;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.swing.*;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;

/**
 * 文件落盘任务实体类
 */
@Data
@NoArgsConstructor
public class PlacingFileTask {
    private Long id;

    private String taskName;

    private Integer fileNum;

    private String fileTotalSize;

    private Long totalTime;

    private Long useTime;

    private Long readedBytes;

    private Long gatherId;

    private Long systemModelId;

    private Long pdwFormatId;

    private Long targetId;

    private String dirPath;

    private String isFinished;

    private Date uploadTime;

    private String userName;

    private String processLog;
    private String customColumn1;
    private String customColumn2;
    private String customColumn3;
    private String customColumn4;
    private String customColumn5;
    private String customColumn6;

    public PlacingFileTask(FileChooserUI fileChooserUI) {
        this.setDirPath(fileChooserUI.folderPathField.getText());
        this.setTaskName(fileChooserUI.taskNameField.getText());
        systemModelId =  Optional.ofNullable(fileChooserUI.getSystemModelComboBox().getSelectedItem()).map((model -> ((DictSystemModel) model).getId())).orElse(null);
        gatherId =  Optional.ofNullable(fileChooserUI.getGatherPlaceComboBox().getSelectedItem()).map((gather -> ((DictGather) gather).getId())).orElse(null);
        targetId =  Optional.ofNullable(fileChooserUI.getTargetObjectComboBox().getSelectedItem()).map((target -> ((DictTarget) target).getId())).orElse(null);
        processLog = fileChooserUI.processLogField.getText();

        customColumn1 = Optional.ofNullable(fileChooserUI.getCustomColumnVs().get(1)).map(JTextField::getText).orElse(null);
        customColumn2 = Optional.ofNullable(fileChooserUI.getCustomColumnVs().get(2)).map(JTextField::getText).orElse(null);
        customColumn3 = Optional.ofNullable(fileChooserUI.getCustomColumnVs().get(3)).map(JTextField::getText).orElse(null);
        customColumn4 = Optional.ofNullable(fileChooserUI.getCustomColumnVs().get(4)).map(JTextField::getText).orElse(null);
        customColumn5 = Optional.ofNullable(fileChooserUI.getCustomColumnVs().get(5)).map(JTextField::getText).orElse(null);
        customColumn6 = Optional.ofNullable(fileChooserUI.getCustomColumnVs().get(6)).map(JTextField::getText).orElse(null);

        this.setIsFinished("0");
    }
}